// 基础类型定义
export type PlayerID = 'player1' | 'player2';
export type LaneID = 'top' | 'mid' | 'bot';
export type CardID = string;
export type HeroID = string;
export type TowerID = `${LaneID}_${PlayerID}`;

// 游戏阶段
export type GamePhase =
  | 'draft'       // 选牌阶段(Artifact特有)
  | 'deployment'  // 部署阶段
  | 'action'      // 行动阶段
  | 'combat'      // 战斗阶段
  | 'end'         // 回合结束阶段
  | 'gameOver';   // 游戏结束

// 卡牌位置类型
export type CardLocation =
  | { type: 'hand', owner: PlayerID }
  | { type: 'lane', lane: LaneID, position: number, owner: PlayerID }
  | { type: 'deck', owner: PlayerID }
  | { type: 'discard', owner: PlayerID }
  | { type: 'shop' } // 商店(物品卡)
  | { type: 'removed' };

// 英雄状态
export interface IHeroState {
  id: HeroID;
  cardId: CardID;
  owner: PlayerID;
  lane: LaneID;
  position: number;
  health: number;
  armor: number;
  attack: number;
  abilities: string[];
  isActive: boolean; // 是否可行动
  cooldown: number;  // 技能冷却
}

// 塔状态
export interface ITowerState {
  id: TowerID;
  health: number;
  armor: number;
  isAncient: boolean; // 是否为基地
}

// 玩家状态
export interface IPlayerState {
  id: PlayerID;
  name: string;
  health: number;      // 玩家生命值(基地生命)
  mana: number;        // 当前法力值
  maxMana: number;     // 最大法力值
  gold: number;        // 金币(用于购买物品)
  deck: CardID[];      // 牌库
  hand: CardID[];      // 手牌
  discardPile: CardID[]; // 弃牌堆
  items: CardID[];     // 物品栏
  heroes: HeroID[];    // 拥有的英雄
  passed: boolean;     // 是否已跳过当前阶段
}

export interface ICardState {
  definitionId: string;    // 卡牌模板ID
  instanceId: CardID;    // 卡牌实例ID
  name: string;
  pointX: number;
  pointY: number;
  imagePath: string;
  location: CardLocation;   // 当前位置
  modifications: any[];   // 状态修改(增益/减益)
}

// 游戏状态接口
export interface IGameState {
  // 游戏元信息
  gameId: string;
  version: string;
  phase: GamePhase;
  turn: number;
  currentPlayer: PlayerID;
  winner?: PlayerID;

  // 玩家数据
  players: Record<PlayerID, IPlayerState>;

  // 战场状态
  lanes: Record<LaneID, {
    cards: CardID[];          // 该路的卡牌(包括英雄和小兵)
    towers: Record<PlayerID, TowerID>; // 该路的塔
  }>;

  // 实体状态
  heroes: Record<HeroID, IHeroState>;
  towers: Record<TowerID, ITowerState>;
  cards: Record<CardID, ICardState>;

  // 游戏历史记录(用于回放/撤销)
  history: {
    action: string;
    data: any;
    timestamp: number;
  }[];

  // 商店状态(物品卡)
  shop?: {
    availableItems: CardID[];
    rerollCost: number;
  };

  // 游戏配置
  config: {
    initialHandSize: number;
    maxHandSize: number;
    maxHeroes: number;
    maxItems: number;
    // 其他游戏规则配置...
  };

  // 时间戳
  lastUpdated: number;
}